package com.cloudmusic.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.cloudmusic.dao.CustomListMapper;
import com.cloudmusic.service.CustomListService;

@Service
@Transactional
public class CustomListServiceimpl implements CustomListService{
	
	@Autowired
	CustomListMapper customListMapper;

	public void addCustomList(String lid, String listname, String uid) {
		customListMapper.addSongList(lid, listname);
		customListMapper.addUserSongList(uid,lid);
	}

	public void updateCustomListName(String lid, String newlistname) {
		customListMapper.updateListName(lid, newlistname);
	}

	public void deleteCustomList(String lid) {
		customListMapper.deleteCustomList(lid);
	}

	public JSONObject selectCustomListMusic(String lid,String uid) {
		List list = customListMapper.selectCustomListMusic(lid);
		for (int i = 0;i<list.size();i++){
			Map map = (Map) list.get(i);
			String sid = (String) map.get("sid");
			int islove = customListMapper.checkMusicLove(uid,sid);
			((Map) list.get(i)).put("islove",islove);
		}
		JSONObject json = new JSONObject();
		json.put("rows", list);
		return json;
	}

	@Override
	public int checkCustomListName(String uid, String listname) {
		int i = customListMapper.checkCustomListName(uid, listname);
		return i;
	}

}
